﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.ServiceModel.Description;
using WcfContrib.Errors;
using WcfContrib.Hosting;

namespace WcfContrib.Showcase.Service
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                ServiceHost<Service> h = new ServiceHost<Service>();

                //One way to add the error handler.. check Service.cs or App.config for other ways
                ErrorContextHandlerBehavior.AddContextHandler(h.Description, new MyErrorHandler());

                h.Open();

                Console.WriteLine("Service is up, press 'Enter to exit'");
                Console.ReadLine();

                h.Close();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Error: " + ex.ToString());
                Console.ReadLine();
            }
        }
    }

    static class Helpers
    {
        internal static void WriteLine(ConsoleColor color, string input, params object[] format)
        {
            ConsoleColor orgColor = Console.ForegroundColor;

            Console.ForegroundColor = color;
            Console.WriteLine(string.Format(input, format));

            Console.ForegroundColor = orgColor;
        }
    }
}
